home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.09 Sep 90 / Object1 Folder / CObject1App.c next >
Encoding:
C/C++ Source or Header  |  1994-11-06  |  3.5 KB  |  183 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * CObject1App.c
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *****/
  7.  
  8. #include "CObject1App.h"
  9. #include "CObject1Doc.h"
  10.  
  11. extern    OSType    gSignature;
  12.  
  13. /***
  14.  * IObject1App
  15.  *
  16.  *    Initialize the application. Your initialization method should
  17.  *    at least call the inherited method. If your application class
  18.  *    defines its own instance variables or global variables, this
  19.  *    is a good place to initialize them.
  20.  *
  21.  ***/
  22.  
  23. void CObject1App::IObject1App(void)
  24.  
  25. {
  26.     CApplication::IApplication(4, 20480L, 2048L);
  27. }
  28.  
  29.  
  30.  
  31. /***
  32.  * SetUpFileParameters
  33.  *
  34.  *    In this routine, you specify the kinds of files your
  35.  *    application opens.
  36.  *
  37.  *
  38.  ***/
  39.  
  40. void CObject1App::SetUpFileParameters(void)
  41.  
  42. {
  43.     inherited::SetUpFileParameters();    /* Be sure to call the default method */
  44.  
  45.         /**
  46.          **    sfNumTypes is the number of file types
  47.          **    your application knows about.
  48.          **    sfFileTypes[] is an array of file types.
  49.          **    You can define up to 4 file types in
  50.          **    sfFileTypes[].
  51.          **
  52.          **/
  53.  
  54.     sfNumTypes = 1;
  55.     sfFileTypes[0] = 'TEXT';
  56.  
  57.         /**
  58.          **    Although it's not an instance variable,
  59.          **    this method is a good place to set the
  60.          **    gSignature global variable. Set this global
  61.          **    to your application's signature. You'll use it
  62.          **    to create a file (see CFile::CreateNew()).
  63.          **
  64.          **/
  65.  
  66.     gSignature = '????';
  67. }
  68.  
  69.  
  70.  
  71. /***
  72.  * DoCommand
  73.  *
  74.  *    Your application will probably handle its own commands.
  75.  *    Remember, the command numbers from 1-1023 are reserved.
  76.  *    The file Commands.h contains all the reserved commands.
  77.  *
  78.  *    Be sure to call the default method, so you can get
  79.  *    the default behvior for standard commands.
  80.  *
  81.  ***/
  82. void CObject1App::DoCommand(long theCommand)
  83.  
  84. {
  85.     switch (theCommand) {
  86.     
  87.         /* Your commands go here */
  88.     
  89.         default:    inherited::DoCommand(theCommand);
  90.                     break;
  91.     }
  92. }
  93.  
  94. /***
  95.  * Exit
  96.  *
  97.  *    Chances are you won't need this method.
  98.  *    This is the last chance your application gets to clean up
  99.  *    things like temporary files.
  100.  *
  101.  ***/
  102.  
  103. void CObject1App::Exit()
  104.  
  105. {
  106.     /* your exit handler here */
  107. }
  108.  
  109.  
  110. /***
  111.  * CreateDocument
  112.  *
  113.  *    The user chose New from the File menu.
  114.  *    In this method, you need to create a document and send it
  115.  *    a NewFile() message.
  116.  *
  117.  ***/
  118.  
  119. void CObject1App::CreateDocument()
  120.  
  121. {
  122.     CObject1Doc    *theDocument;
  123.     
  124.     theDocument = new(CObject1Doc);
  125.         
  126.         /**
  127.          **    Send your document an initialization
  128.          **    message. The first argument is the
  129.          **    supervisor (the application). The second
  130.          **    argument is TRUE if the document is printable.
  131.          **
  132.          **/
  133.     
  134.     theDocument->IObject1Doc(this, TRUE);
  135.  
  136.         /**
  137.          **    Send the document a NewFile() message.
  138.          **    The document will open a window, and
  139.          **    set up the heart of the application.
  140.          **
  141.          **/
  142.     theDocument->NewFile();
  143. }
  144.  
  145. /***
  146.  * OpenDocument
  147.  *
  148.  *    The user chose Open… from the File menu.
  149.  *    In this method you need to create a document
  150.  *    and send it an OpenFile() message.
  151.  *
  152.  *    The macSFReply is a good SFReply record that contains
  153.  *    the name and vRefNum of the file the user chose to
  154.  *    open.
  155.  *
  156.  ***/
  157.  
  158. void CObject1App::OpenDocument(SFReply *macSFReply)
  159.  
  160. {
  161.     CObject1Doc    *theDocument;
  162.     
  163.     theDocument = new(CObject1Doc);
  164.         
  165.         /**
  166.          **    Send your document an initialization
  167.          **    message. The first argument is the
  168.          **    supervisor (the application). The second
  169.          **    argument is TRUE if the document is printable.
  170.          **
  171.          **/
  172.     
  173.     theDocument->IObject1Doc(this, TRUE);
  174.  
  175.         /**
  176.          **    Send the document an OpenFile() message.
  177.          **    The document will open a window, open
  178.          **    the file specified in the macSFReply record,
  179.          **    and display it in its window.
  180.          **
  181.          **/
  182.     theDocument->OpenFile(macSFReply);
  183. }